<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item  prop="operEnterpriseName">
        <el-input
          v-model="queryParams.operEnterpriseName"
          placeholder="设备运营商-企业名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item  prop="operEnterpriseDockingName">
        <el-input
          v-model="queryParams.operEnterpriseDockingName"
          placeholder="设备运营商-对接人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item  prop="operEnterpriseDockingPhone">
        <el-input
          v-model="queryParams.operEnterpriseDockingPhone"
          placeholder="设备运营商-对接人电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item  prop="operOperatorSecret">
        <el-input
          v-model="queryParams.operOperatorSecret"
          placeholder="设备运营商-运营商秘钥"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item  prop="operSigSecret">
        <el-input
          v-model="queryParams.operSigSecret"
          placeholder="设备运营商-签名秘钥"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item  prop="operDataSecret">
        <el-input
          v-model="queryParams.operDataSecret"
          placeholder="设备运营商-数据加密秘钥"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item  prop="operDataSecretIv">
        <el-input
          v-model="queryParams.operDataSecretIv"
          placeholder="设备运营商-初始化向量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <!-- <el-form-item  prop="operReqUrl">
        <el-input
          v-model="queryParams.operReqUrl"
          placeholder="设备运营商-请求地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->

      <el-form-item  prop="userEnterpriseName">
        <el-input
          v-model="queryParams.userEnterpriseName"
          placeholder="用户平台-企业名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item  prop="userEnterpriseDockingName">
        <el-input
          v-model="queryParams.userEnterpriseDockingName"
          placeholder="用户平台-对接人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item  prop="userEnterpriseDockingPhone">
        <el-input
          v-model="queryParams.userEnterpriseDockingPhone"
          placeholder="用户平台-对接人电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item  prop="userOperatorSecret">
        <el-input
          v-model="queryParams.userOperatorSecret"
          placeholder="用户平台-运营商秘钥"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item  prop="userSigSecret">
        <el-input
          v-model="queryParams.userSigSecret"
          placeholder="用户平台-签名秘钥"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item  prop="userDataSecret">
        <el-input
          v-model="queryParams.userDataSecret"
          placeholder="用户平台-数据加密秘钥"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item  prop="userDataSecretIv">
        <el-input
          v-model="queryParams.userDataSecretIv"
          placeholder="用户平台-初始化向量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <!-- <el-form-item  prop="userReqUrl">
        <el-input
          v-model="queryParams.userReqUrl"
          placeholder="请输入用户平台-请求地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->

      <el-form-item  prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_normal_disable"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['bus:busDockingInfo:add']"
        >新增</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['bus:busDockingInfo:edit']"
        >修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['bus:busDockingInfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['bus:busDockingInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="busDockingInfoList" @selection-change="handleSelectionChange" border>
      <el-table-column type="selection" width="55" align="center" fixed />
      <el-table-column label="ID" align="center" prop="id" fixed />
      <el-table-column label="设备运营商-企业名称" align="center"  prop="operEnterpriseName" width="120" show-overflow-tooltip/>
      <el-table-column label="设备运营商-对接人姓名" align="center" prop="operEnterpriseDockingName" width="120" show-overflow-tooltip />
      <el-table-column label="设备运营商-对接人电话" align="center" prop="operEnterpriseDockingPhone"  width="120" show-overflow-tooltip/>
      <el-table-column label="设备运营商-运营商秘钥" align="center" prop="operOperatorSecret" width="120" show-overflow-tooltip />
      <el-table-column label="设备运营商-签名秘钥" align="center" prop="operSigSecret" width="120" show-overflow-tooltip />
      <el-table-column label="设备运营商-数据加密秘钥" align="center" prop="operDataSecret" width="120" show-overflow-tooltip />
      <el-table-column label="设备运营商-初始化向量" align="center" prop="operDataSecretIv" width="120" show-overflow-tooltip/>
      <el-table-column label="设备运营商-请求地址" align="center" prop="operReqUrl" width="120" show-overflow-tooltip/>
      <el-table-column label="状态" align="center" prop="status" width="120" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="用户平台-企业名称" align="center" prop="userEnterpriseName" width="120" show-overflow-tooltip/>
      <el-table-column label="用户平台-对接人姓名" align="center" prop="userEnterpriseDockingName" width="120" show-overflow-tooltip/>
      <el-table-column label="用户平台-对接人电话" align="center" prop="userEnterpriseDockingPhone" width="120" show-overflow-tooltip/>
      <el-table-column label="用户平台-运营商秘钥" align="center" prop="userOperatorSecret" width="120" show-overflow-tooltip/>
      <el-table-column label="用户平台-签名秘钥" align="center" prop="userSigSecret" width="120" show-overflow-tooltip/>
      <el-table-column label="用户平台-数据加密秘钥" align="center" prop="userDataSecret" width="120" show-overflow-tooltip/>
      <el-table-column label="用户平台-初始化向量" align="center" prop="userDataSecretIv" width="120" show-overflow-tooltip/>
      <el-table-column label="用户平台-请求地址" align="center" prop="userReqUrl" width="120" show-overflow-tooltip/>
      <el-table-column label="操作" align="center" fixed="right" width="180" class-name="small-padding fixed-width">
        <template slot-scope="scope">

          <el-button
            size="mini"
            type="text" 
            icon="el-icon-refresh-left"
            @click="handleRefreshToken(scope.row)"
            v-hasPermi="['bus:busDockingInfo:edit']"
          >测试</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['bus:busDockingInfo:edit']"
          >修改</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['bus:busDockingInfo:remove']"
          >删除</el-button>

        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改对接信息登录对话框 -->
    <el-drawer
      :title="title"
      :visible.sync="open"
      size="60%"
      append-to-body
      :wrapperClosable=false
      direction="rtl">


        <el-form ref="form" :model="form" :rules="rules" label-width="15%">

         <el-card style="margin: 10px 10px;">
            <div slot="header" class="clearfix">
              <span style="font-weight: 600;font-size: 15px;color: #46a6ff;">设备运营商信息</span>
            </div>
            
            <el-form-item label="企业组织机构代码" prop="operEnterpriseCode">
              <el-input v-model="form.operEnterpriseCode" placeholder="请输入企业组织机构代码" />
            </el-form-item>
            <el-form-item label="企业名称" prop="operEnterpriseName">
              <el-input v-model="form.operEnterpriseName" placeholder="请输入企业名称" />
            </el-form-item>
            <el-form-item label="对接人姓名" prop="operEnterpriseDockingName">
              <el-input v-model="form.operEnterpriseDockingName" placeholder="请输入对接人姓名" />
            </el-form-item>
            <el-form-item label="对接人电话" prop="operEnterpriseDockingPhone">
              <el-input v-model="form.operEnterpriseDockingPhone" placeholder="请输入对接人电话" />
            </el-form-item>
            <el-form-item label="运营商秘钥" prop="operOperatorSecret">
              <el-input v-model="form.operOperatorSecret" placeholder="请输入运营商秘钥" />
            </el-form-item>
            <el-form-item label="签名秘钥" prop="operSigSecret">
              <el-input v-model="form.operSigSecret" placeholder="请输入签名秘钥" />
            </el-form-item>
            <el-form-item label="数据加密秘钥" prop="operDataSecret">
              <el-input v-model="form.operDataSecret" placeholder="请输入数据加密秘钥" />
            </el-form-item>
            <el-form-item label="初始化向量" prop="operDataSecretIv">
              <el-input v-model="form.operDataSecretIv" placeholder="请输入初始化向量" />
            </el-form-item>
            <el-form-item label="请求地址" prop="operReqUrl">
              <el-input v-model="form.operReqUrl" placeholder="请输入请求地址" />
            </el-form-item>
        </el-card>


        <el-card style="margin: 10px 10px 80px 10px;">
          <div slot="header" class="clearfix">
            <span style="font-weight: 600;font-size: 15px;color: #46a6ff;">用户平台信息</span>
          </div>

          <el-form-item label="企业组织机构代码" prop="userEnterpriseCode">
              <el-input v-model="form.userEnterpriseCode" placeholder="请输入企业组织机构代码" />
            </el-form-item>
          <el-form-item label="企业名称" prop="userEnterpriseName">
            <el-input v-model="form.userEnterpriseName" placeholder="请输入企业名称" />
          </el-form-item>
          <el-form-item label="对接人姓名" prop="userEnterpriseDockingName">
            <el-input v-model="form.userEnterpriseDockingName" placeholder="请输入对接人姓名" />
          </el-form-item>
          <el-form-item label="对接人电话" prop="userEnterpriseDockingPhone">
            <el-input v-model="form.userEnterpriseDockingPhone" placeholder="请输入对接人电话" />
          </el-form-item>
          <el-form-item label="运营商秘钥" prop="userOperatorSecret">
            <el-input v-model="form.userOperatorSecret" placeholder="请输入运营商秘钥" />
          </el-form-item>
          <el-form-item label="签名秘钥" prop="userSigSecret">
            <el-input v-model="form.userSigSecret" placeholder="请输入签名秘钥" />
          </el-form-item>
          <el-form-item label="数据加密秘钥" prop="userDataSecret">
            <el-input v-model="form.userDataSecret" placeholder="请输入数据加密秘钥" />
          </el-form-item>
          <el-form-item label="初始化向量" prop="userDataSecretIv">
            <el-input v-model="form.userDataSecretIv" placeholder="请输入初始化向量" />
          </el-form-item>
          <el-form-item label="请求地址" prop="userReqUrl">
            <el-input v-model="form.userReqUrl" placeholder="请输入请求地址" />
          </el-form-item>
          <el-form-item label="状态" prop="status">
            <el-select v-model="form.status" placeholder="请选择状态">
              <el-option
                v-for="dict in dict.type.sys_normal_disable"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-card>    
          
      </el-form>
      

      <div class="demo-drawer__footer">
        <el-button type="primary" icon="el-icon-circle-check" @click="submitForm">确 定</el-button>
        <el-button icon="el-icon-close" @click="cancel">取 消</el-button>
      </div>
      
    </el-drawer>

  </div>
</template>

<script>
import { listBusDockingInfo, getBusDockingInfo, delBusDockingInfo, addBusDockingInfo, updateBusDockingInfo,refreshToken } from "@/api/bus/busDockingInfo";

export default {
  name: "BusDockingInfo",
  dicts: ['sys_normal_disable'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 对接信息登录表格数据
      busDockingInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        operEnterpriseName: null,
        operEnterpriseDockingName: null,
        operEnterpriseDockingPhone: null,
        operOperatorSecret: null,
        operSigSecret: null,
        operDataSecret: null,
        operDataSecretIv: null,
        operReqUrl: null,
        userEnterpriseName: null,
        userEnterpriseDockingName: null,
        userEnterpriseDockingPhone: null,
        userOperatorSecret: null,
        userSigSecret: null,
        userDataSecret: null,
        userDataSecretIv: null,
        userReqUrl: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
         operEnterpriseCode: [
          { required: true, message: "设备运营商-组织机构代码不能为空", trigger: "blur" }
        ],
         userEnterpriseCode: [
          { required: true, message: "用户平台-组织机构代码不能为空", trigger: "blur" }
        ],
        operEnterpriseName: [
          { required: true, message: "设备运营商-企业名称不能为空", trigger: "blur" }
        ],
        operEnterpriseDockingName: [
          { required: true, message: "设备运营商-对接人姓名不能为空", trigger: "blur" }
        ],
        operEnterpriseDockingPhone: [
          { required: true, message: "设备运营商-对接人电话不能为空", trigger: "blur" }
        ],
        operOperatorSecret: [
          { required: true, message: "设备运营商-运营商秘钥不能为空", trigger: "blur" }
        ],
        operSigSecret: [
          { required: true, message: "设备运营商-签名秘钥不能为空", trigger: "blur" }
        ],
        operDataSecret: [
          { required: true, message: "设备运营商-数据加密秘钥(data部分加密秘钥)不能为空", trigger: "blur" }
        ],
        operDataSecretIv: [
          { required: true, message: "设备运营商-数据加密秘钥(data部分加密秘钥)不能为空", trigger: "blur" }
        ],
        operReqUrl: [
          { required: true, message: "设备运营商-请求地址不能为空", trigger: "blur" }
        ],
        userEnterpriseName: [
          { required: true, message: "用户平台-企业名称不能为空", trigger: "blur" }
        ],
        userEnterpriseDockingName: [
          { required: true, message: "用户平台-对接人姓名不能为空", trigger: "blur" }
        ],
        userEnterpriseDockingPhone: [
          { required: true, message: "用户平台-对接人电话不能为空", trigger: "blur" }
        ],
        userOperatorSecret: [
          { required: true, message: "用户平台-运营商秘钥不能为空", trigger: "blur" }
        ],
        userSigSecret: [
          { required: true, message: "用户平台-签名秘钥不能为空", trigger: "blur" }
        ],
        userDataSecret: [
          { required: true, message: "用户平台-数据加密秘钥(data部分加密秘钥)不能为空", trigger: "blur" }
        ],
        userDataSecretIv: [
          { required: true, message: "用户平台-数据加密秘钥(data部分加密秘钥)不能为空", trigger: "blur" }
        ],
        userReqUrl: [
          { required: true, message: "用户平台-请求地址不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "状态不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询对接信息登录列表 */
    getList() {
      this.loading = true;
      listBusDockingInfo(this.queryParams).then(response => {
        this.busDockingInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        operEnterpriseName: null,
        userEnterpriseCode: null,
        operEnterpriseCode: null,
        operEnterpriseDockingName: null,
        operEnterpriseDockingPhone: null,
        operOperatorSecret: null,
        operSigSecret: null,
        operDataSecret: null,
        operDataSecretIv: null,
        operReqUrl: null,
        userEnterpriseName: null,
        userEnterpriseDockingName: null,
        userEnterpriseDockingPhone: null,
        userOperatorSecret: null,
        userSigSecret: null,
        userDataSecret: null,
        userDataSecretIv: null,
        userReqUrl: null,
        status: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加对接信息登录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getBusDockingInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改对接信息登录";
      });
    },
    /** 测试-从新获取一个新的token */
    handleRefreshToken(row){
      this.$modal.confirm('将会获取一个新的token来测试连通性,确认执行操作？').then(function() {
        return refreshToken(row.id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("测试通过");
      }).catch(() => {});
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateBusDockingInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBusDockingInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除对接信息登录编号为"' + ids + '"的数据项？').then(function() {
        return delBusDockingInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('bus/busDockingInfo/export', {
        ...this.queryParams
      }, `busDockingInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>


<style>
  .demo-drawer__footer {
    position: absolute;
    bottom: 0;
    width: 100%;
    padding: 0 12px 0 20px;
    background-color: #fff;
    border-top: 1px solid #d9d9d9;
    height: 60px;
    line-height: 60px;
    z-index: 999999;
  }


  .el-dropdown-menu__item {
    font-size: 12px;
    color: #1890ff;
  }
</style>